//
// Created by cuichao on 2023/3/6.
//
#include <modbus/modbus.h>
#include <cstdio>
#include <cstring>

static modbus_t *client = nullptr;
static float global_v = 1.0;

bool create_modbus_client(const char *port_name, int baudrate) {
    return true;
}

void set_slave(int slave_id) {
}

int read_detector(int detector_address, int detector_count, float *values, char *const errmsg) {

    if (detector_count <= 0 || detector_address <= 0) {
        const char *err = "节点地址和读取长度必须大于零";
        strcpy(errmsg, err);
        return 0;
    }

    for (int i = 0; i < detector_count; ++i) {
        *values++ = global_v++;
    }

    return detector_count;

}

void stop_modbus() {
    printf("关闭modbus client!\n");
}